package cn.itcast.travel.service.impl;

import cn.itcast.travel.dao.UserDao;
import cn.itcast.travel.dao.impl.UserDaoImpl;
import cn.itcast.travel.domain.FandV;
import cn.itcast.travel.domain.User;
import cn.itcast.travel.service.UserService;

import java.util.List;

public class UserServiceImpl implements UserService{


    private UserDao userDao = new UserDaoImpl();
    /**
     * 注册用户
     * @param
     * @return
     */
    @Override
    public boolean regist(User user) {
        //1.根据用户名查询用户对象
        User u = userDao.findByUsername(user.getUsername());
        //判断u是否为null
        if(u != null){
            //用户名存在，注册失败
            return false;
        }
        //2.保存用户信息
        //2.1设置激活码，唯一字符串
       /* user.setCode(UuidUtil.getUuid());
        //2.2设置激活状态
        user.setStatus("N");*/
        userDao.save(user);

        //3.激活邮件发送，邮件正文？

        /*String content="<a href='http://localhost/travel/activeUserServlet?code="+user.getCode()+"'>点击激活【黑马旅游网】</a>";

        MailUtils.sendMail(user.getEmail(),content,"激活邮件");*/
        return true;
    }

    //*
     //* 激活用户
     //* @param code
     //* @return

 /*   @Override
    public boolean active(String code) {
        //1.根据激活码查询用户对象
        User user = userDao.findByCode(code);
        if(user != null){
            //2.调用dao的修改激活状态的方法
            userDao.updateStatus(user);
            return true;
        }else{
            return false;
        }
    }*/



    /**
     * 登录方法
     * @param user
     * @return
     */
    @Override
    public User login(User user) {
        return userDao.findByUsernameAndPassword(user.getUsername(),user.getPassword());
    }

    /**
     * 模糊查询水产
     * @param fandV
     * @return
     */
    @Override
    public List<FandV> Amohuchaxun(FandV fandV) {
        return userDao.Amohuchaxun(fandV);
    }

    /**
     * 模糊查询肉类
     * @param fandV
     * @return
     */
    @Override
    public List<FandV> Mmohuchaxun(FandV fandV) {
        return userDao.Mmohuchaxun(fandV);
    }

    /**
     * 模糊查询水果
     * @param fandV
     * @return
     */
    @Override
    public List<FandV> Fmohuchaxun(FandV fandV) {

        return userDao.Fmohuchaxun(fandV);
    }

    /**
     * 查询所有蔬菜水果信息的方法
     * @return
     */
    @Override
    public List<FandV> FV_findall() {
        return userDao.FandVfindAll();
    }

    /**
     * 添加蔬菜水果商品信息
     * @param fandV
     * @return
     */
    @Override
    public void charuFV(FandV fandV) {
        userDao.saveFV(fandV);

    }

    /**
     * 根据id删除指定数据
     * @param fandV
     * @return
     */
    @Override
    public String de_FV(FandV fandV) {
        userDao.deFV(fandV);
        return userDao.deFV(fandV);
    }

    /**
     * 修改
     * @param fandV
     */
    @Override
    public void findID_FV(FandV fandV) {
        userDao.findxiugaiIDFV(fandV);
    }


    /*水产*/
    @Override
    public List<FandV> FA_findall() {
        return userDao.FandAfindAll();
    }

    @Override
    public void charuFA(FandV fandV) {
        userDao.saveFA(fandV);
    }

    @Override
    public String de_FA(FandV fandV) {
        return userDao.deFA(fandV);
    }

    @Override
    public void findID_FA(FandV fandV) {
        userDao.findxiugaiIDFA(fandV);
    }


    /*肉类*/
    @Override
    public List<FandV> FM_findall() {
        return userDao.FandMfindAll();    }

    @Override
    public void charuFM(FandV fandV) {
        userDao.saveFM(fandV);

    }

    @Override
    public String de_FM(FandV fandV) {
        return userDao.deFM(fandV);
    }

    @Override
    public void findID_FM(FandV fandV) {
        userDao.findxiugaiIDFM(fandV);

    }


}
